//
//  ViewController.m
//  iosFlutterApp
//
//  Created by flutterDev on 2024/10/28.
//

#import "ViewController.h"
#import <Flutter/Flutter.h>

@interface ViewController (){
    FlutterMethodChannel *methodChannel;
    int count;
}
@property (nonatomic,strong) FlutterViewController *flutterVC;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    //初始化页面、通信Channel
    self.flutterVC = [[FlutterViewController alloc] init];
    methodChannel = [FlutterMethodChannel methodChannelWithName:@"methodOne" binaryMessenger:self.flutterVC.binaryMessenger];
    
    //注册监听
    __weak typeof(self) weakSelf = self;
    [methodChannel setMethodCallHandler:^(FlutterMethodCall * _Nonnull call, FlutterResult  _Nonnull result) {
            if ([call.method isEqualToString:@"exit"]) {
                [weakSelf.flutterVC dismissViewControllerAnimated:YES completion:nil];
            }
    }];
}

- (IBAction)onclick_push:(id)sender {
    count++;
    NSString *valueStr = [NSString stringWithFormat:@"update_%d",count];
    
    //向flutter发送消息
    [methodChannel invokeMethod:valueStr arguments:nil];
    [self presentViewController:self.flutterVC animated:YES completion:nil];
}
@end
